#!/bin/bash

WP=$1

if command -v "feh" >/dev/null 2>&1; then
    feh --bg-fill "$WP" 2> /dev/null
elif command -v "nitrogen" >/dev/null 2>&1; then
    nitrogen --set-zoom-fill --save "$WP" 2> /dev/null
fi

# Awesome Window Manager
if [[ "$XDG_SESSION_DESKTOP $DESKTOP_STARTUP_ID $DESKTOP_SESSION $XDG_CURRENT_DESKTOP" == *"awesome"* ]]; then
	echo "local gears = require(\"gears\") gears.wallpaper.maximized(\"$1\", nil)" | awesome-client
fi

# =====================================================================================

# OPTIONAL: Show a notification on automatic wallpaper change.
# Display the original filename in the notification, but actually apply the post-effects image.
name=$(echo "$3" | sed 's/\//\n/g'| tail -n 1)
if [ "$2" == "auto" ]; then notify-send --icon "$WP" "Wallpaper changed" "$name" ; fi

exit 0
